﻿using System;
using System.Windows.Forms;

namespace DosTexPrj.UI.WinForm.Commons
{
    public static class Common
    {
        public static bool IsBlankTextBox(System.Windows.Forms.Control control, string Text, System.Windows.Forms.ErrorProvider error)
        {
            bool isBlank = true;
            if (string.IsNullOrEmpty(control.Text.Trim()))
            {
                error.SetError(control, Text);
                isBlank = false;
            }
            return isBlank;
        }

        public static bool IsCorrectDate(DateTime before, DateTime after, string Text, System.Windows.Forms.Control control, System.Windows.Forms.ErrorProvider error)
        {
            bool isBefore = true;
            if (before > after)
            {
                error.SetError(control, Text);
                isBefore = false;
            }
            return isBefore;
        }

        public static bool IsBlankCombobox(System.Windows.Forms.ComboBox combobox, string Text, System.Windows.Forms.ErrorProvider error)
        {
            bool isBlank = true;
            if (combobox.SelectedIndex < 0)
            {
                error.SetError(combobox, Text);
                isBlank = false;
            }
            return isBlank;
        }

        public static void HandlingNumberTextbox(KeyPressEventArgs e)
        {
            if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+")
                && !e.KeyChar.Equals((Char)Keys.Delete)
                && !e.KeyChar.Equals((Char)Keys.Back))
                e.Handled = true;
        }
    }
}